home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Graphics / QuickDraw GX / GX->PostScript Sample / GXToPostScript / Imaging Engine / HalftonePrimitive.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  6.8 KB  |  270 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        HalftonePrimitive.c
  3.  
  4.      Contains:    QuickDraw GX to PostScript conversion code.
  5.                          File contains routines for setting the
  6.                         current halftone screens of the PostScript
  7.                         device.
  8.  
  9.      Version:    Technology:    Quickdraw GX 1.1.x
  10.       
  11.      Copyright:    © 1992-1997 by Apple Computer, Inc., all rights reserved.
  12. */
  13.  
  14. #include "GXToPSBuildConfig.h"
  15. #include <GXGraphics.h>
  16. #include "GXGraphicsPriv.h"
  17. #include <GXEnvironment.h>
  18. #include "GXToPostScript.h"
  19. #include "IOUtilities.h"
  20. #include "RDUtil.h"
  21. #include "FontHandler.h"
  22. #include "PublicPostScriptIE.h"
  23. #include "private.h"
  24. #include "PSIEResources.h"
  25. #include "GXErrors.h"
  26. #include "ShapeUtilities.h"
  27.  
  28. #ifdef resumeLabel
  29.     #undef resumeLabel
  30. #endif
  31. #define resumeLabel(exception)
  32.  
  33.  
  34. /**********************************
  35.  
  36.     Routine: OutputScreenParams:
  37.     
  38.     Routine puts the angle, frequency and spot function
  39.     for a halftone record on the stack.
  40.  
  41. ***********************************/
  42. OSErr    OutputScreenParams(TRDParams*    pRDParams, gxHalftone* pHalftone);
  43. OSErr    OutputScreenParams(TRDParams*    pRDParams, gxHalftone* pHalftone)
  44.     {
  45.         OSErr                        status;
  46.         unsigned char        *spotFname;
  47.         
  48.         switch(pHalftone->method) {
  49.         
  50.             case gxRoundDot:
  51.                 spotFname = "\p/RoundDotFunction";
  52.                 break;
  53.                 
  54.             case gxSpiralDot:
  55.                 spotFname = "\p/SpiralDotFunction";
  56.                 break;
  57.                 
  58.             case gxLineDot:
  59.                 spotFname = "\p/LineDotFunction";
  60.                 break;
  61.                 
  62.             case gxEllipticDot:
  63.                 spotFname = "\p/EllipticDotFunction";
  64.                 break;
  65.                 
  66.             case gxTriangleDot:
  67.                 spotFname = "\p/TriangleDotFunction";
  68.                 break;
  69.                 
  70.             case gxDispersedDot:
  71.                 spotFname = "\p/DispersedDotFunction";
  72.                 break;
  73.             
  74.             case gxSquareDot:
  75.                 spotFname = "\p/SquareDotFunction";
  76.                 break;
  77.                 
  78.             #if DEBUGLEVEL > 0
  79.             default:
  80.                 dprintf(notrace, "Bug, Don't know halftone method: %d", pHalftone->method);
  81.             #endif
  82.         
  83.         }//end switch
  84.     
  85.         pRDParams->resIndex = kDoScreenParams;
  86.         status = RDResPrintf(pRDParams, pHalftone->frequency, pHalftone->angle, spotFname);
  87.         ncheck(status);
  88.         
  89.         return(status);
  90.     
  91.     }//OutputScreenParams
  92.  
  93.  
  94. //<FF>
  95. /******************************************
  96.  
  97.     Routine DoSetScreen:
  98.     
  99.     Routine sets the current halftone screen for
  100.     a black and white device.
  101.     
  102. *******************************************/
  103. OSErr    DoSetScreen(TIEGlobalsHdl hIEGlobals, gxHalftone* theHalftone);
  104. OSErr    DoSetScreen(TIEGlobalsHdl hIEGlobals, gxHalftone* theHalftone)
  105.     {
  106.         OSErr                        status;
  107.         TIEGlobalsPtr        pGlobals;    
  108.         TRDParams*            pRDParams;
  109.     
  110.         pGlobals = *hIEGlobals;
  111.         pRDParams = pGlobals->pRDParams;
  112.  
  113.         nrequire(status = OutputScreenParams(pRDParams, theHalftone), failed_Screen);
  114.         
  115.         pRDParams->resIndex = kSetHalftone;
  116.         nrequire(status = RDResPrintf(pRDParams, 1), failed_Screen);    
  117.  
  118. failed_Screen:
  119.         return(status);
  120.     
  121.     }//DoSetScreen
  122.  
  123. /******************************************
  124.  
  125.     Routine DoSetColorScreen:
  126.     
  127.     Routine sets the current halftone screen for
  128.     a color device.
  129.     
  130. *******************************************/
  131. OSErr    DoSetColorScreen(TIEGlobalsHdl hIEGlobals, gxHalftone* cHalftone, gxHalftone* mHalftone, gxHalftone* yHalftone, gxHalftone* kHalftone);
  132. OSErr    DoSetColorScreen(TIEGlobalsHdl hIEGlobals, gxHalftone* cHalftone, gxHalftone* mHalftone, gxHalftone* yHalftone, gxHalftone* kHalftone)
  133.     {
  134.         OSErr                        status;
  135.         TIEGlobalsPtr        pGlobals;    
  136.         TRDParams*            pRDParams;
  137.     
  138.         pGlobals = *hIEGlobals;
  139.         pRDParams = pGlobals->pRDParams;
  140.  
  141.         nrequire(status = OutputScreenParams(pRDParams, cHalftone), failed_Screen);
  142.         nrequire(status = OutputScreenParams(pRDParams, mHalftone), failed_Screen);
  143.         nrequire(status = OutputScreenParams(pRDParams, yHalftone), failed_Screen);
  144.         nrequire(status = OutputScreenParams(pRDParams, kHalftone), failed_Screen);
  145.         
  146.         pRDParams->resIndex = kSetHalftone;
  147.         nrequire(status = RDResPrintf(pRDParams, 4), failed_Screen);    
  148.  
  149. failed_Screen:
  150.         return(status);
  151.     
  152.     }//DoSetScreen
  153.  
  154. //<FF>
  155. /******************************************
  156.  
  157.     Routine HalftonePrimitive:
  158.     
  159.     Routine sets the current screen on the PostScript
  160.     device based upone the halftone information provided.
  161.     
  162.     It picks the best halftone or set of halftone records
  163.     from the provided list depending upon the device's 
  164.     color space.
  165.     
  166. *******************************************/
  167. OSErr _HalftonePrimitive(TIEGlobalsHdl hIEGlobals, gxFormatHalftoneInfo *halftoneInfo)
  168.     {
  169.         OSErr                        status;
  170.         gxColorSpace        devCspace;
  171.         long                        i;
  172.         gxHalftone*            pHalftone;                            // pointer into array.
  173.  
  174.         /** Determine whether or not to use color or monochrome screens **/
  175.         
  176.         devCspace = (*hIEGlobals)->params.devCSpace;
  177.         
  178.         if (devCspace == gxGraySpace) {
  179.         
  180.             /****
  181.                     find the halftone record to use, either the luminanceTint if it is there,
  182.                     or the fromBlack, else just the first one in the record.
  183.             **/
  184.             gxHalftone*                pGrayHalftone = nil;
  185.             
  186.             pHalftone = halftoneInfo->halftones;
  187.             
  188.             for (i = halftoneInfo->numHalftones -1 ; i >= 0; --i) {
  189.             
  190.                 if (pHalftone->tinting == gxLuminanceTint) {
  191.                 
  192.                     pGrayHalftone = pHalftone;
  193.                     break;                                                    // look no further
  194.                     
  195.                 } else if (pHalftone->tinting == gxComponent4Tint) {        // we may have to use the black
  196.                 
  197.                     pGrayHalftone = pHalftone;            // but keep looking.
  198.                     
  199.                 }//end if
  200.                 
  201.                 ++pHalftone;
  202.             
  203.             }//end for
  204.             
  205.             if (pGrayHalftone == nil)
  206.                 pGrayHalftone = halftoneInfo->halftones;            // if we couldn't find anything just use first.
  207.                 
  208.             nrequire(status = DoSetScreen(hIEGlobals, pGrayHalftone), failed_GrayHalftone);
  209.             
  210.         
  211.         } else {
  212.         
  213.             /** Find the four halftone records to use **/
  214.             gxHalftone*        pCyanHalftone = nil;
  215.             gxHalftone*        pMagentaHalftone = nil;
  216.             gxHalftone*        pYellowHalftone = nil;
  217.             gxHalftone*        pBlackHalftone = nil;
  218.         
  219.             pHalftone = halftoneInfo->halftones;
  220.             
  221.             for (i = halftoneInfo->numHalftones -1 ; i >= 0; --i) {
  222.             
  223.                 if (pHalftone->tinting == gxComponent1Tint)
  224.                     pCyanHalftone = pHalftone;
  225.                     
  226.                 else if (pHalftone->tinting == gxComponent2Tint)
  227.                     pMagentaHalftone = pHalftone;
  228.                     
  229.                 else if (pHalftone->tinting == gxComponent3Tint)
  230.                     pYellowHalftone = pHalftone;
  231.                     
  232.                 else if (pHalftone->tinting == gxComponent4Tint)
  233.                     pBlackHalftone = pHalftone;
  234.                     
  235.                 else if ((pHalftone->tinting == gxLuminanceTint) && (pBlackHalftone == nil) )
  236.                     pBlackHalftone = pHalftone;
  237.                     
  238.                 ++pHalftone;
  239.             
  240.             }//end for
  241.             
  242.             if (pBlackHalftone == nil)
  243.                 pBlackHalftone = halftoneInfo->halftones;                // just use first, if there was no black.
  244.             
  245.             /** Use the black record for any not found **/
  246.             
  247.             if (pCyanHalftone == nil)
  248.                 pCyanHalftone = pBlackHalftone;
  249.                 
  250.             if (pMagentaHalftone == nil)
  251.                 pMagentaHalftone = pBlackHalftone;
  252.                 
  253.             if (pYellowHalftone == nil)
  254.                 pYellowHalftone = pBlackHalftone;
  255.                 
  256.             status = DoSetColorScreen(hIEGlobals, pCyanHalftone, pMagentaHalftone,
  257.                                                                                         pYellowHalftone, pBlackHalftone);
  258.             
  259.             nrequire(status, failed_ColorHalftone);
  260.         
  261.         }//end if
  262.  
  263. failed_ColorHalftone:    
  264. failed_GrayHalftone:
  265.  
  266.         return(status);
  267.     
  268.     }//HalftonePrimitive
  269.  
  270.